package com.cz;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import java.util.Date;
import java.util.Map;

/**
 * @program: raip-security
 * @Date: 2020/4/15 10:55
 * @Author: lunan
 * @Description:
 */
public class Aa {

 public static void main(String[] args) {
  //创建动态客户端
  JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
  String [] options = { "autoNameResolution" };
  factory.setSchemaCompilerOptions(options);
  Client client = factory.createClient("http://192.168.0.8:7100/Service.asmx?WSDL");
  // 需要密码的情况需要加上用户名和密码
  //client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
  HTTPConduit conduit = (HTTPConduit) client.getConduit();
  HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
  httpClientPolicy.setConnectionTimeout(2000);  //连接超时
  httpClientPolicy.setAllowChunking(false);    //取消块编码
  httpClientPolicy.setReceiveTimeout(120000);     //响应超时
  conduit.setClient(httpClientPolicy);
  //client.getOutInterceptors().addAll(interceptors);//设置拦截器
  try {

//   Date date = new Date();


   Date date = DateUtil.parse("2020-04-28 13:00:00");

   JSONObject parameters = new JSONObject();

   parameters.put("StartDate", DateUtil.format(date, "yyyy-MM-dd HH:mm:ss"));

System.out.println("aaaaa---"+parameters.toJSONString());
   Object[] objects = new Object[0];
   // invoke("方法名",参数1,参数2,参数3....);
   objects = client.invoke("GetSellMasterByCode", "7F20626E185E9B28",parameters.toJSONString());
   System.out.println("返回数据:" + objects[0]);

   Map maps = (Map) JSON.parse(objects[0].toString());
   System.out.println("这个是用JSON类来解析JSON字符串!!!");
   for (Object map : maps.entrySet()){
   System.out.println(((Map.Entry)map).getKey()+"     " + ((Map.Entry)map).getValue());
   }

   JSONArray datas = (JSONArray) JSON.parse(maps.get("Data").toString());

   if(datas.size() > 0){

     for(int i = 0;i < datas.size();i++){
      JSONObject job = datas.getJSONObject(i);

     }
   }
   System.out.println("datas--"+datas.toString());
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}
